/**
 * Created by jt on 2017/5/6.
 */
import "./index.less";
import "../../../unit/common/js/bootstrap_js/jquery.min.js";
import "../../../unit/common/js/bootstrap_js/ckeditor.js";
import "../../../unit/common/js/bootstrap_js/select2.min.js";
import "../../../unit/common/js/bootstrap_js/jquery.multi-select.js";
import "../../../unit/common/js/bootstrap_js/jquery.dataTables.js";
import "../../../unit/common/js/bootstrap_js/form-samples.js";
import "../../../unit/common/js/bootstrap_js/table-editable.js";
import "../../../unit/common/js/bootstrap_js/bootstrap-datetimepicker.js";
import "../../../unit/common/js/bootstrap_js/bootstrap-datetimepicker.zh-CN.js";
import "../../../unit/common/js/bootstrap_js/form-components.js";

import paginationTpl from "./paging.handlebars";
import matListTpl from "./getMatList.handlebars";
import matInfsTpl from "./matInfs.handlebars";
import matDtlTpl from "./matDtl.handlebars";
import suitCompaniesTpl from "./suitCompanies.handlebars";
import designatedSplrsTpl from "./designatedSplrs.handlebars";
import selectSplrsTpl from "./selectSplrs.handlebars";
import atchesTpl from "./atches.handlebars";

import {StringUtils} from "../../../unit/common/js/common/StringUtils";

let projId = getArgs().id;
let orgList = sessionStorage.getItem("manageCompanies");
let orgId = sessionStorage.getItem("orgId");
let realName = sessionStorage.getItem("realName");
let mobilephone = sessionStorage.getItem("mobilephone");
let token = sessionStorage.getItem('token');
// let ctct = sessionStorage.getItem('ctct');
// let ctctTel = sessionStorage.getItem('ctctTel');
let bidDept = sessionStorage.getItem('bidDept');
let bidDeptAddr = sessionStorage.getItem('bidDeptAddr');
// 物料信息是否从请购需求中导入，默认为true
var matFromReqFlg = true;
// var matlist = [];

let picFlag = true;
if(realName != null && realName !=''){
    jQuery('.ctct').val(realName);
}
if(mobilephone != null && mobilephone !=''){
    jQuery('.ctctTel').val(mobilephone);
}
if (token == null || token =='') {
    location.href = HOST_FRT+'/logins/login.html';
}

let orgJsonObj = JSON.parse(orgList);
if(orgJsonObj.length){
    for(var i=0; i<orgJsonObj.length; i++){
        if(orgJsonObj[i].parent_dept_id==1){
            var selected="";
            if(orgJsonObj[i].id==orgId){
                selected = "selected";
            }
            jQuery('.orgId').append('<option value="'+orgJsonObj[i].id+'" ' + selected + '>'+orgJsonObj[i].dept_name+'</option>');
            // $(".controls.OrgIds").append('<input type="checkbox" value="'+orgJsonObj[i].id+'">'+orgJsonObj[i].dept_name);
            // $(".controls.OrgIds input[value="+orgJsonObj[i].id+"]").data("bindComp",orgJsonObj[i]);
        }
    }
}else{
    alert("该采购员无所辖公司");
    location.href = HOST_FRT+'/bid_online/proj_list.html';
}


var ProjEdit = {

    pageNo: 1,
    pageSize: 10,
    maxPage: 1,
    isFirstPage: false,
    isLastPage: false,
    total: 0,
    bidDept: bidDept,
    bidDeptAddr: bidDeptAddr,
    bidOpenTim : '',
    bidEndTim : '',
    projMemo : '',
    allMatTypeList:[],         //所有分类列表
    allMatTypeParentList:[],  //所有一级分类列表
    matkl2html: {},             //所有二级分类列表
    selectedMatCodList:[],    //已保存的物料code
    selectedReqIdList : [],   // 已保存的req_id
    allReqIdList : [],         // 所有请购单中req_id
    nowTime : new Date().Format("yyyy-MM-dd hh:mm"),
    orgIds: '',                 // 适用公司IDs
    init : function() {
        let self = ProjEdit;
        this.getMatType()
            .then(this.getCurrTyp)
            .then(this.getProjData)
            .then(this.renderData)
            // .then(this.getReqGoods)
            // .then(this.renderPagination)
            .then(this.bindEvent);
    },

    // 根据公司ID获取公司信息
    getCompanyByOrgId : function (oid) {
        let companies = JSON.parse(orgList);

        for(var i=0; i< companies.length; i++){
            if(companies[i].id == oid) {
                return StringUtils.cvtObjNil({
                    "id" : companies[i].id,
                    "deptCode" : companies[i].dept_code,
                    "ctct" : companies[i].ctct,
                    "parentDeptId" : companies[i].parent_dept_id,
                    "bidDept" : companies[i].bidDept,
                    "parentDeptName" : companies[i].parent_dept_name,
                    "ctctTel" : companies[i].ctctTel,
                    "bidDeptAddr" : companies[i].bidDeptAddr
                });
            }
        }

        return {};
    },

    //获取物料品类
    getMatType : function(){
        let self = ProjEdit;
        return new Promise((resolve, reject)=>{
            jQuery.ajax({
                url: HOST_ADDR+'/cpmp/mat/matSapType',
                type: 'get',
                dataType: 'json',
                contentType:"application/json",
                headers: {
                    'access_token': token,'login_type':'ums'
                },
                success: function(resp){
                    if (resp.success && resp.data) {
                        self.allMatTypeList = resp.data;
                        for (var i=0;i<resp.data.length;i++) {
                            var matkl1 = resp.data[i].matkl1;
                            if(self.allMatTypeParentList.indexOf(matkl1) < 0){
                                self.allMatTypeParentList.push(matkl1);
                                $('.matTyp.matkl1').append('<option value="'+resp.data[i].matkl1+'">'+resp.data[i].matkl1name+'</option>');
                                self.matkl2html[matkl1] = '<option value="'+resp.data[i].matkl1+'">'+resp.data[i].matkl1name+'(全部)</option><option value="'+resp.data[i].matkl2+'">'+resp.data[i].matkl2name+'</option>';
                            }else{
                                self.matkl2html[matkl1] += '<option value="'+resp.data[i].matkl2+'">'+resp.data[i].matkl2name+'</option>';
                            }
                        }
                        $('.matTyp.matkl1').on("change",function(){
                            $('.matTyp.matkl2').html("");
                            var tmpmatkl1 = $('.matTyp.matkl1').val();
                            if(tmpmatkl1){
                                $('.matTyp.matkl2').html(self.matkl2html[tmpmatkl1]);
                            }
                        });
                        resolve();
                    }else{
                        alert(resp.msgCod+' '+resp.msgInf);
                    }
                },
                error:function(err){
                    console.log(err);
                }
            });
        });
    },

    // 获取币种
    getCurrTyp: function(){
        let self = ProjEdit;
        return new Promise((resolve, reject) => {
            const parmTyps = 'CURR_TYP';
            const url = HOST_ADDR + '/cpmp/comParm/getByParmTyp/' + parmTyps;
            $.ajax({
                url: url,
                type: 'get',
                dataType: 'json',
                headers:{
                   'access_token': token,
                   'login_type': 'ums'
                },
                contentType: 'application/json',
                success: function(resp) {
                    if (!resp.success) {
                        alert(resp.msgCod + " - " + resp.msgInf);
                        console.log(resp.msgCod + " - " + resp.msgInf);
                        return ;
                    }
                    if (jQuery.isArray(resp.data)) {
                        $.each(resp.data,function(idx,val){
                            jQuery('.currTyp').append('<option exRate="' + val.parmVal + '" value="' + val.parmCod + '">' + val.parmMemo + '</option>');
                        });
                    }
                    resolve();
                },
                error: function(err) {
                    console.log(err);
                }
            });
        });
    },


    getProjData:function(rsp){
        const self = ProjEdit;
        return new Promise((resolve, reject)=>{
            if (projId!=null && projId!='' && projId!='undefined'){
                // jQuery('.orgId').attr("disabled","disabled");
                //编辑（需先获取已保存的信息）
                jQuery.ajax({
                    url: HOST_ADDR + '/cpmp/bidProjOnMngForPchs/view/' + projId,
                    type: 'get',
                    dataType: 'json',
                    contentType: "application/json",
                    headers: {
                        'access_token': token, 'login_type': 'ums'
                    },
                    success: function (resp) {
                        if (resp.success) {
                            resolve(resp);
                        }else{
                            alert(resp.msgCod + ' ' + resp.msgInf);
                        }
                    },
                    error: function (err) {
                        console.log(err);
                    }
                });
            }else{
                resolve(rsp);
            }
        });
    },

    // 渲染表单
    renderData: function(resp) {
        const self = ProjEdit;
        return new Promise((resolve, reject) => {
            var data = {};
            if (typeof resp == 'undefined' || resp == null || resp == '') {
                data = {
                    "bidProjOn" : {
                        "bidRngTyp" : "0",
                        "matOri" : "0",
                        "bidDpst" : "0.0",
                        "dpstFlg" : "0",
                        "currTyp" : "RMB",
                        "grdRul" : "0"
                    }
                    , 'splrs' : []
                    , 'atches' : []
                };
            }

            if(typeof(resp)!="undefined" && resp!='' && resp!=null){
                data = resp.data;
                // TODO
                if (resp.data.bidProjOn.bidOpenTim != null && resp.data.bidProjOn.bidOpenTim !='') {
                    self.bidOpenTim = (new Date(resp.data.bidProjOn.bidOpenTim)).Format("yyyy-MM-dd hh:mm");
                }
                if (resp.data.bidProjOn.bidEndTim != null && resp.data.bidProjOn.bidEndTim !='') {
                    self.bidEndTim = (new Date(resp.data.bidProjOn.bidEndTim)).Format("yyyy-MM-dd hh:mm");
                }
                if (resp.data.bidProjOn.projMemo != null && resp.data.bidProjOn.projMemo !='') {
                    self.projMemo = resp.data.bidProjOn.projMemo;
                }
                self.bidDeptAddr = resp.data.bidProjOn.bidDptAddr;
                self.bidDept = resp.data.bidProjOn.bidDptNam;
                if(resp.data.bidProjOn.orgId != null && resp.data.bidProjOn.orgId !=''){
                    jQuery('.orgId').val(resp.data.bidProjOn.orgId);
                }
                if(resp.data.bidProjOn.ctct != null){
                    jQuery('.ctct').val(resp.data.bidProjOn.ctct);
                }
                if(resp.data.bidProjOn.ctctTel != null){
                    jQuery('.ctctTel').val(resp.data.bidProjOn.ctctTel);
                }
                if(resp.data.bidProjOn.projSupv != null){
                    jQuery('.projSupv').val(resp.data.bidProjOn.projSupv);
                }
                if(resp.data.bidProjOn.projSupvTel != null){
                    jQuery('.projSupvTel').val(resp.data.bidProjOn.projSupvTel);
                }
                for(var i=0;i<self.allMatTypeList.length;i++){
                    if(resp.data.bidProjOn.matTyp==self.allMatTypeList[i].matkl1 || resp.data.bidProjOn.matTyp==self.allMatTypeList[i].matkl2){
                        if(!jQuery('.matTyp.matkl1').val()){
                            jQuery('.matTyp.matkl1').val(self.allMatTypeList[i].matkl1);
                            jQuery('.matTyp.matkl2').html(self.matkl2html[self.allMatTypeList[i].matkl1]);
                            jQuery('.matTyp.matkl2').val(resp.data.bidProjOn.matTyp);
                        }
                    }
                }
                jQuery('.projNam').val(resp.data.bidProjOn.projNam);
                jQuery('.qotCntTyp').val(resp.data.bidProjOn.qotCntTyp);
                jQuery('.bidRngTyp').val(resp.data.bidProjOn.bidRngTyp);
                jQuery('.currTyp').val(resp.data.bidProjOn.currTyp);
                // jQuery('.exRate').val("当前汇率: " + )

                jQuery('.pubPriFlg').val(resp.data.bidProjOn.pubPriFlg);

                resp.data.bidProjOn.matOri = '1';
                $.each(data.matDtls,function(idx,elem){
                    if (elem.reqId != null && elem.reqId != '' && typeof (elem.reqId) != 'undefined') {
                        resp.data.bidProjOn.matOri = '0';
                    }
                    elem.dlvDteStr = elem.dlvDte ? (new Date(elem.dlvDte)).Format("yyyy-MM-dd") : '';
                });
            }

            // 物料来源相关
            var matOri = data.bidProjOn.matOri;
            if (typeof(matOri) == 'undefined' || matOri == null || matOri == '') {
                matOri = '0';
            }
            jQuery('.matOrgin').val(matOri);
            projEditObj.setMatOri();

            // 评标相关
            var grdRul = data.bidProjOn.grdRul;
            if (StringUtils.isEmptyStr(grdRul)) {
                grdRul = '0';
            }
            jQuery('.grdRul').val(grdRul);
            projEditObj.setGrdRul();

            // 适用公司相关
            // if (matOri === '1') {  // 非请购需求
            //     var orgIds = data.bidProjOn.sutOrgIds;
            //     if (orgIds != null && typeof orgIds != 'undefined' && orgIds != '') {
            //         var orgidlist = orgIds.split(",");
            //         if (jQuery.isArray(orgidlist)) {
            //             if(orgidlist.length > 0){   // 已选择的适用公司IDs.
            //                 let cboxs = jQuery('.selectedCompanies');
            //                 if (cboxs.length > 0) {
            //                     for (let i = 0; i < cboxs.length; i++) {
            //                         for(let j = 0; j < orgidlist.length; j++) {
            //                             if (cboxs.eq(i).val() === orgidlist[j]) {
            //                                 cboxs.eq(i).attr('checked','checked');
            //                             }
            //                         }
            //
            //                     }
            //                 }
            //             }
            //         }
            //     }
            // }

            // 招标范围相关
            var bidRngTyp = data.bidProjOn.bidRngTyp;
            if (typeof(bidRngTyp) == 'undefined' || bidRngTyp == null || bidRngTyp == '') {
                bidRngTyp = '0';
            }
            jQuery('.bidRngTyp').val(bidRngTyp);
            projEditObj.changeBidRngTyp();
            // 若为定向招标
            if (bidRngTyp === '1') {
                if (data.splrs != null && data.splrs != '') {
                    projEditObj.displayDesignatedSplrs(data.splrs);
                }
            }

            // 附件相关
            projEditObj.displayAtches(data.atches);

            // 物料相关
            projEditObj.displayMatInfs(data.matDtls);

            // 设置适用公司
            self.orgIds = data.bidProjOn.sutOrgIds;

            // 当前汇率
            jQuery('.exRate').val("当前汇率：" + $(".currTyp option:selected").attr('exRate'));

            // 投标保证金
            var dpstFlg = data.bidProjOn.dpstFlg;
            if (dpstFlg == null || dpstFlg == '' || typeof (dpstFlg) == 'undefined' || dpstFlg == '0') {
                jQuery('.dpstFlg').val('0');
                jQuery('.bidDpst').attr('disabled','disabled').val(0);
            } else {
                jQuery('.dpstFlg').val(data.bidProjOn.dpstFlg);
                jQuery('.bidDpst').removeAttr('disabled');
                jQuery('.bidDpst').val(data.bidProjOn.bidDpst);
            }


            jQuery('.projMemo').val(self.projMemo);
            jQuery('.bidOpenTimStr').val(self.bidOpenTim);
            jQuery('.bidEndTimStr').val(self.bidEndTim);
            jQuery('.bidDptAddr').val(self.checkNull(self.bidDeptAddr));
            jQuery('.bidDptNam').val(self.checkNull(self.bidDept));
            resolve();
        });
    },


    // 获取请购单物料
    getReqGoods: function() {
        const self = ProjEdit;
        return new Promise((resolve, reject) => {

            let orgId = jQuery('.orgId').val();

            jQuery.ajax({
                url: HOST_ADDR+'/cpmp/bidProjOnMngForPchs/getReqMatInfs/'+self.pageNo+'/'+self.pageSize+'/'+orgId,
                type: 'get',
                dataType: 'json',
                contentType:"application/json",
                headers: {
                    'access_token': token,'login_type':'ums'
                },
                success: function(resp){
                    if (!resp.success || !resp.data) {
                        alert(resp.msgCod+' '+resp.msgInf);
                        self.pageNo = 1;
                        self.total = 0;
                        self.isFirstPage = 0;
                        self.isLastPage = 0;
                        self.maxPage = 1;
                        let resultHtml = matListTpl();
                        $('#tab3_addMore_modal').html(resultHtml);
                        resolve();
                        return;
                    }

                    self.total = resp.data.count;
                    self.isFirstPage = self.pageNo === 1;
                    self.maxPage = Math.ceil(self.total / self.pageSize);
                    if(self.pageNo * self.pageSize >= self.total){
                        self.isLastPage = true;
                    }else{
                        self.isLastPage = false;
                    }
                    $.each(resp.data.list,function(index,item){
                        item.dlvDteStr = item.dlvDte ? (new Date(item.dlvDte)).Format("yyyy-MM-dd") : '';
                    });
                    let resultdata = resp.data.list;
                    let resultHtml = matListTpl({matList: resultdata});
                    $('#tab3_addMore_modal').html(resultHtml);
                    resolve();
                },
                error:function(err){
                    console.log(err);
                }
            });
            // }else{
            //     resolve();
            // }
        });
    },


    // 渲染分页
    renderPagination: function(){
        let self = ProjEdit;
        let pageList = [];
        for(let i=0; i<self.maxPage; i++){
            pageList.push({idx: i+1});
        }

        let paginationHtml = paginationTpl({
            begin: (self.pageNo-1) * self.pageSize + 1,
            end: self.isLastPage ? self.total : self.pageNo * self.pageSize,
            total: self.total,
            isLastPage: self.isLastPage,
            isFirstPage: self.isFirstPage,
            pageList: pageList

        });
        $('.J_pagination').html(paginationHtml);
        $('.page-item').each((index,item)=>{
            if($(item).data('index')===self.pageNo){
                $(item).addClass('active');
            }

            //最多显示7个页码
            if (Math.abs($(item).data('index')-self.pageNo) > 3) {
                $(item).css('display','none');
            }
        });
    },

    getPostData: function(){
        $(".bitian").each(function(){
            var val = $(this).val().trim();
            var labelname = $(this).parent().prev().text().slice(1,-1);
            if(val==''){
                alert(labelname+"不能为空！");
                return false;
            }
        })

        let orgId = jQuery('.orgId').val();
        let projName = jQuery('.projNam').val();
        let bidDptNam = jQuery('.bidDptNam').val();
        let bidDptAddr = jQuery('.bidDptAddr').val();
        let matTyp = jQuery('.matTyp.matkl2').val();
        let qotCntTyp = jQuery('.qotCntTyp').val();
        let bidDpst = jQuery('.bidDpst').val();
        let ctct = jQuery('.ctct').val();
        let ctctTel = jQuery('.ctctTel').val();
        let bidRngTyp = jQuery('.bidRngTyp').val();
        let projMemo = jQuery('.projMemo').val();
        let currTyp = jQuery('.currTyp').val();
        let dpstFlg = jQuery('.dpstFlg').val();
        let pubPriFlg = jQuery('.pubPriFlg').val();
        let projSupv = jQuery('.projSupv').val();
        let projSupvTel = jQuery('.projSupvTel').val();
        let grdRul = jQuery('.grdRul').val();
        let atchDtos = [];
        // let atchDiv = jQuery('.atchDiv');
        let splrIds = '';
        let orgIds = orgId;  // 适用公司(已弃用)
        let matList =[];

        // 指定招标供应商
        if (bidRngTyp === '1') {
            let splrIdList = [];
            let designatedSplrObjs = jQuery('#designatedSplrs tr');
            for (let j = 0; j < designatedSplrObjs.length; j++) {
                splrIdList.push(designatedSplrObjs.eq(j).find('td').eq(0).text());
            }
            splrIds = splrIdList.join(',');
            if(splrIds == null || splrIds == '') {
                alert("定向招标时，指定招标供应商不得为空！");
                return false;
            }
        }
        // 物料
        let matInfsObj = jQuery('#matInfs tr');
        for (let j = 0; j < matInfsObj.length; j++) {
            if(matInfsObj.eq(j).find('td').eq(6).text()==''){
                alert('交货时间不得为空！');
            }
            matList.push({
                "projId":projId,
                "reqId": matInfsObj.eq(j).find('td').eq(0).text(),
                "matCod": matInfsObj.eq(j).find('td').eq(1).text(),
                "matNam": matInfsObj.eq(j).find('td').eq(2).text(),
                "matUnt": matInfsObj.eq(j).find('td').eq(3).text(),
                "pchsNum": matInfsObj.eq(j).find('td').eq(4).text(),
                "dlvAdr": matInfsObj.eq(j).find('td').eq(5).text(),
                "dlvDteStr": matInfsObj.eq(j).find('td').eq(6).text()+' 00:00:00',
                "techServ": matInfsObj.eq(j).find('td').eq(7).text(),
                "memo": matInfsObj.eq(j).find('td').eq(8).text()
            });
        }
        if (matList.length == 0) {
            alert('物料信息不得为空！');
            return false;
        }
        // 附件
        let atchesObj = jQuery('#atches tr');
        for (let j = 0; j < atchesObj.length; j++) {
            atchDtos.push({
                "atchUrl": atchesObj.eq(j).attr('atchUrl'),
                "atchNam": atchesObj.eq(j).attr('atchNam')
            });
        }
        var tel1 = /^1(3|4|5|7|8)\d{9}$/;
        var tel2 = /^\d{3,4}-?\d{7,9}$/;
        if ((!tel1.test(ctctTel) && !tel2.test(ctctTel)) || (!tel1.test(projSupvTel) && !tel2.test(projSupvTel))) {
            alert('请填写正确格式的联系电话！');
            return false;
        }
        if (!/^\d+(\.\d{0,2})?$/.test(bidDpst)){
            alert('保证金必须为数字，最多保留两位小数！');
            return false;
        }
        let data = {
            "orgId":orgId,
            "sutOrgIds": orgIds,
            "projId":projId,
            "projNam": projName,
            "bidDptNam": bidDptNam,
            "bidDptAddr": bidDptAddr,
            "matTyp":matTyp,
            "qotCntTyp":qotCntTyp,
            "bidDpst":bidDpst,
            "ctct":ctct,
            "ctctTel":ctctTel,
            "bidRngTyp":bidRngTyp,
            "projMemo":projMemo,
            "bidOpenTimStr":jQuery('.bidOpenTimStr').val()+':00',
            "bidEndTimStr":jQuery('.bidEndTimStr').val()+':00',
            "splrIds":splrIds,
            "matList":matList,
            "currTyp":currTyp,
            "dpstFlg":dpstFlg,
            "pubPriFlg":pubPriFlg,
            "projSupv":projSupv,
            "projSupvTel":projSupvTel,
            "grdRul" : grdRul,
            "atchDtos": atchDtos
        };
        return data;
    },

    // 验证表单
    // checkForm: function(orgId,projName,bidDptNam,bidDptAddr,matTyp,qotCntTyp,dpstFlg,bidDpst,currTyp,pubPriFlg,ctct,ctctTel,bidRngTyp, grdRul){
    //     if (orgId == ''){
    //         alert("请选择发起公司！");
    //         return false;
    //     }
    //     if (projName == '') {
    //         alert('请填写项目名称！');
    //         return false;
    //     }
    //     if (bidDptNam == '') {
    //         alert('请填写单位名称！');
    //         return false;
    //     }
    //     if (bidDptAddr == '') {
    //         alert('请填写单位地址！');
    //         return false;
    //     }
    //     if (matTyp == '') {
    //         alert('请填写物料品类！');
    //         return false;
    //     }
    //     if (qotCntTyp == '') {
    //         alert('请填写报价类型！');
    //         return false;
    //     }
    //     if (dpstFlg == '') {
    //         alert('请选择是否需要投标保证金！');
    //         return false;
    //     }
    //     if (dpstFlg == '1') {
    //         if (bidDpst == '') {
    //             alert('请填写投标保证金！');
    //             return false;
    //         } else if (!/^\d+(\.\d{0,2})?$/.test(bidDpst)){
    //             alert('保证金必须为数字，最多保留两位小数！');
    //             return false;
    //         }
    //     }
    //     if (currTyp == '') {
    //         alert('请选择币种！');
    //         return false;
    //     }
    //     if (pubPriFlg == '') {
    //         alert('请选择是否需要公开招标价格！');
    //         return false;
    //     }
    //
    //     if (ctct == '') {
    //         alert('请填写联系人！');
    //         return false;
    //     }
    //     if (ctctTel == '') {
    //         alert('请填写联系电话！');
    //         return false;
    //     } else {
    //         var tel1 = /^1(3|4|5|7|8)\d{9}$/;
    //         var tel2 = /^\d{3,4}-?\d{7,9}$/;
    //         if (!tel1.test(ctctTel) && !tel2.test(ctctTel)) {
    //             alert('请填写正确格式的联系电话！');
    //             return false;
    //         }
    //     }
    //     if (bidRngTyp == '') {
    //         alert('请填写招标范围类型！');
    //         return false;
    //     }
    //     if (grdRul == '') {
    //         alert('请填写评标规则！');
    //         return false;
    //     }
    //     return true;
    // },
    checkNull: function(val) {
        if (val !=null && val !='' && val !='undefined') {

        } else { val = '';}
        return val;
    },
    renderList:function(){
        let self = ProjEdit;
        self.getReqGoods()
            .then(self.renderPagination)
            .then(self.bindEvent);
    },
    bindEvent:function(){
        let self = ProjEdit;
        $('.J_prev').unbind().click(function(){
            if(self.pageNo > 1){
                self.pageNo = self.pageNo -1;
                self.renderList();
            }
        });
        $('.J_next').unbind().click(function(){
            if(self.pageNo < self.maxPage){
                self.pageNo = self.pageNo + 1;
                self.renderList();
            }
        });

        //首尾页
        $('.isFirst').unbind().click(function(){
            if(self.pageNo != 1){
                self.pageNo = 1;
                self.renderList();
            }
        });
        $('.isLast').unbind().click(function(){
            if(self.pageNo != self.maxPage){
                self.pageNo = self.maxPage;
                self.renderList();
            }
        });
        $('.page-item').unbind().click(function(){
            let $item = $(this);

            if(!$item.hasClass('active')){
                self.pageNo = $item.data('index');
                self.renderList();
            }
        });

        // 删除物料
        $(".toDelete").unbind("click").on("click",function(){
            var reqId = parseInt($(this).parent().parent().find(".pid").attr("reqId"));
            var index = self.selectedReqIdList.indexOf(reqId);
            if(index > -1){
                self.selectedReqIdList.splice(index,1);
            }
            $(this).parent().parent().remove();
        });

        // 取消按钮
        $(".toCancel").unbind("click").on("click",function(){
            $(".modal-backdrop").click();
        });

        var flg = true;
        // 保存   提交审核
        jQuery(".form-actions a[type='submit']").unbind("click").on("click",function(){
            let subFlg = 0; // 保存
            if(!flg){
                alert("请勿重复提交");
                return false;
            }
            if(jQuery(this).hasClass("subCheck")){  // 提交审核
                subFlg = 1; // 提交审核
            }else if(jQuery(this).hasClass("subKeep")){
                subFlg = 0; // 保存
            }else{
                return false;
            }
            // let orgId = jQuery('.orgId').val();
            // let projName = jQuery('.projNam').val();
            // let bidDptNam = jQuery('.bidDptNam').val();
            // let bidDptAddr = jQuery('.bidDptAddr').val();
            // let matTyp = jQuery('.matTyp.matkl2').val();
            // let qotCntTyp = jQuery('.qotCntTyp').val();
            // let bidDpst = jQuery('.bidDpst').val();
            // let ctct = jQuery('.ctct').val();
            // let ctctTel = jQuery('.ctctTel').val();
            // let bidRngTyp = jQuery('.bidRngTyp').val();
            // let projMemo = jQuery('.projMemo').val();
            // let currTyp = jQuery('.currTyp').val();
            // let dpstFlg = jQuery('.dpstFlg').val();
            // let pubPriFlg = jQuery('.pubPriFlg').val();
            // let grdRul = jQuery('.grdRul').val();
            // let atchDtos = [];
            // // let atchDiv = jQuery('.atchDiv');
            // let splrIds = '';
            // let orgIds = orgId;
            // let matList =[];

            // 1. 适用公司
            // var matOrgin = $(".matOrgin").val();
            // orgIds = orgId;
            // 若物料来源为请购需求，则使用公司与发起公司一致
            // if (matOrgin === '0') {
            //     orgIds = orgId;
            // } else {
            //     let orgIdList = [];
            //     jQuery(".selectedCompanies:checked").each(function() {
            //         orgIdList.push(jQuery(this).val());
            //     });
            //     orgIds = orgIdList.join(',');
            // }
            // if(orgIds == null || orgIds == '') {
            //     alert("请选择适用公司！");
            //     return;
            // }


            // 指定招标供应商
            // if (bidRngTyp === '1') {
            //     let splrIdList = [];
            //
            //     let designatedSplrObjs = jQuery('#designatedSplrs tr');
            //     for (let j = 0; j < designatedSplrObjs.length; j++) {
            //         splrIdList.push(designatedSplrObjs.eq(j).find('td').eq(0).text());
            //     }
            //
            //     splrIds = splrIdList.join(',');
            //     if(splrIds == null || splrIds == '') {
            //         alert("定向招标时，指定招标供应商不得为空！");
            //         return;
            //     }
            //
            // }


            // 物料
            // let matInfsObj = jQuery('#matInfs tr');
            // for (let j = 0; j < matInfsObj.length; j++) {
            //     if(matInfsObj.eq(j).find('td').eq(6).text()==''){
            //         alert('交货时间不得为空！');
            //     }
            //     matList.push({
            //         "projId":projId,
            //         "reqId": matInfsObj.eq(j).find('td').eq(0).text(),
            //         "matCod": matInfsObj.eq(j).find('td').eq(1).text(),
            //         "matNam": matInfsObj.eq(j).find('td').eq(2).text(),
            //         "matUnt": matInfsObj.eq(j).find('td').eq(3).text(),
            //         "pchsNum": matInfsObj.eq(j).find('td').eq(4).text(),
            //         "dlvAdr": matInfsObj.eq(j).find('td').eq(5).text(),
            //         "dlvDteStr": matInfsObj.eq(j).find('td').eq(6).text()+' 00:00:00',
            //         "techServ": matInfsObj.eq(j).find('td').eq(7).text(),
            //         "memo": matInfsObj.eq(j).find('td').eq(8).text()
            //     });
            // }
            // if (matList.length == 0) {
            //     alert('物料信息不得为空！');
            //     return;
            // }

            // 附件
            // let atchesObj = jQuery('#atches tr');
            // for (let j = 0; j < atchesObj.length; j++) {
            //     atchDtos.push({
            //         "atchUrl": atchesObj.eq(j).attr('atchUrl'),
            //         "atchNam": atchesObj.eq(j).attr('atchNam')
            //     });
            // }
            //
            // if(!self.checkForm(orgId,projName,bidDptNam,bidDptAddr,matTyp,qotCntTyp,dpstFlg,bidDpst,currTyp,pubPriFlg,ctct,ctctTel,bidRngTyp, grdRul)){
            //     return;
            // }

            var data = self.getPostData();
            if(data && flg){
                flg = false;
                setTimeout(function(){
                    flg = true;
                },3000);

                data.subFlg = subFlg;
                jQuery.ajax({
                    url: HOST_ADDR+'/cpmp/bidProjOnMngForPchs/saveOrSub',
                    type: 'post',
                    data: JSON.stringify(data),
                    dataType: 'json',
                    contentType:"application/json",
                    headers: {
                        'access_token': token,'login_type':'ums'
                    },
                    success: function(resp){
                        if (resp.success) {
                            subFlg==1 ? alert("提交成功！") : alert("保存成功！");
                            location.href = '/bid_online/proj_list.html';
                        }else{
                            alert(resp.msgCod+' '+resp.msgInf);
                        }
                    },
                    error:function(err){
                        console.log(err);
                    }
                });
            }
        })
    }
};

jQuery('.datetimepicker').datetimepicker({
    language: 'zh-CN',
    weekStart: 1,
    todayBtn: 1,
    autoclose: 1,
    todayHighlight: 1,
    startView: 2,
    minView: 0, //0表示分钟（默认），1表示小时，而2表示天
    forceParse: 0,
    showMeridian: 1,
    format: 'yyyy-mm-dd hh:ii'///
});

// 切换发起公司
$(".orgId").change(function() {
    var orgid = $(this).val();
    let company = ProjEdit.getCompanyByOrgId(orgid);
    jQuery('.bidDptAddr').val(company.bidDeptAddr);
    jQuery('.bidDptNam').val(company.bidDept);
});

// 切换评标规则
$(".grdRul").change(function() {
    projEditObj.setGrdRul();
});

// 保证金
jQuery('.dpstFlg').change(function () {
    if (jQuery(this).val() == 0) {
        jQuery('.needPri').hide();
        jQuery('.bidDpst').attr('disabled','disabled');
        jQuery('.bidDpst').val(0);
    } else if (jQuery(this).val() == 1) {
        jQuery('.needPri').show();
        jQuery('.bidDpst').removeAttr('disabled');
        jQuery('.bidDpst').val('');
    }
});

//多选框全选
jQuery("#checkChoose").on("change",function(){
    if(jQuery("#checkChoose").parent().hasClass("checked")){
        jQuery(".checksList").attr("checked",true);
    }else{
        jQuery(".checksList").attr("checked",false);
    }
});

jQuery("#tab3_addMore").on("change",".checksList",function(){
    var len = jQuery(".checksList").length;
    var sel = jQuery(".checksList:checked").length;
    if(len==sel){
        jQuery("#checkChoose").parent().addClass("checked");
    }else{
        jQuery("#checkChoose").parent().removeClass("checked");
    }
});

// 选择添加
$(".myfooter.tools .toAdd").on("click",function() {
    // 1. 数据组装
    var matList = projEditObj.getMatInfs();
    if($("#tab3_addMore_modal .save_more .checksList:checked").length) {
        $("#tab3_addMore_modal .save_more .checksList:checked").each(function() {
            var obj = $(this).parent().parent().parent();
            var matInf = {
                "reqId" : $(obj).attr("reqId"),
                "matNam" : $(obj).attr("matNam"),
                "matCod" : $(obj).attr("matCod"),
                "pchsNum" : $(obj).attr("pchsNum"),
                "matUnt" : $(obj).attr("matUnt"),
                "dlvAdr" : $(obj).attr("dlvAdr"),
                "dlvDteStr" : $(obj).attr("dlvDteStr")
            };
            for (i = 0; i < matList.length; i++) {
                if (matList[i].reqId === matInf.reqId && matList[i].matCod === matInf.matCod) {
                    // alert("需求编号[" + matlist[i].reqIdFmt + "], 物料编号[" + matlist[i].matCod + "]重复添加");
                    return ;
                }
            }
            matList.push(matInf);
        });
    }
    // 2. 展示到页面
    projEditObj.displayMatInfs(matList);
});

// 单笔添加物料
$(".addMatDtl").on("click", function () {
    var matDtl = {};
    jQuery('.matDtlTable .matCod').removeAttr("disabled");
    projEditObj.displayMatDtl(matDtl);
    jQuery('.addOrModMatDtl').attr('addOrMod', 'add');
});


//新增附件
jQuery('.addFile').click(function () {
    jQuery('#atchFile').click();
    $("#atchFile").unbind().change(function(){
        picFlag = false;
        let formData = new FormData();
        let atchNam=$("#atchFile")[0].files[0].name;
        let atchUrl;
        formData.append('file', $("#atchFile")[0].files[0]);
        $.ajax({
            url: HOST_ADDR+'/cpmp/file/upload/atch',
            type: 'post',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            success: function(resp){
                if(resp.success){
                    console.log(resp);
                    atchUrl = resp.data;
                    let atches = projEditObj.getAtches();
                    atches.push({
                        "atchUrl" : atchUrl,
                        "atchNam" : atchNam
                    });

                    projEditObj.displayAtches(atches);

                }else{
                    alert(resp.msgInf);
                }
            },
            error:function(err){
                alert('上传文件失败！');
            }
        });
    });
});


// 从Excel中导入物料信息
jQuery('.importFromExcel').click(function () {
    jQuery('#matInfFile').click();
    $("#matInfFile").unbind().change(function(){
        picFlag = false;
        let formData = new FormData();
        let fileName = $("#matInfFile")[0].files[0].name;
        let url = HOST_ADDR + '/cpmp/bidProjOnMngForPchs/getMatInfsFromExcel';
        formData.append('file', $("#matInfFile")[0].files[0]);
        $.ajax({
            url: url,
            type: 'post',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            success: function(resp){
                if(resp.success){
                    console.log(resp);

                    // 1. 组装数据
                    $.each(resp.data,function(index,item){
                        item.reqId = checkNull(item.reqId);
                    });

                    let matInfs = projEditObj.getMatInfs();
                    let tmpMatInfs = resp.data;

                    for (let j = 0; j < matInfs.length; j++) {
                        for (let k = 0; k < tmpMatInfs.length; k++) {
                            if (matInfs[j].matCod == tmpMatInfs[k].matCod) {
                                alert('物料编码[' + matInfs[j].matCod + ']与现有重复');
                                return ;
                            }
                        }
                    }

                    for (let j = 0; j < tmpMatInfs.length; j++) {
                        matInfs.push(tmpMatInfs[j]);
                    }

                    // 2. 展示到页面
                    projEditObj.displayMatInfs(matInfs);

                    // 3. 彈框消失
                    $('#showMatInfsOfXsl').modal('hide');
                }else{
                    alert(resp.msgInf);
                }
            },
            error:function(err){
                alert('上传文件失败！');
            }
        });
    });
});

jQuery(".matOrgin").change(function () {
    projEditObj.setMatOri();
});

//定向招标获取供应商
jQuery('.bidRngTyp').change(function () {
    projEditObj.changeBidRngTyp();
});

jQuery('.currTyp').change(function () {
    // console.log(exRate);
    jQuery('.exRate').val("当前汇率：" + $(".currTyp option:selected").attr('exRate'));
});

function checkNull(val) {
    if (val !=null && val !='' && val !='undefined') {

    } else { val = '';}
    return val;
}



var projEditObj = {

    init : function () {
       // projEditObj.displayManagedCompanies();
    },

    getMatDtlInf: function (matDtlObj) {
        var matDtl = {
            "reqId": matDtlObj.find('td').eq(0).text(),
            "matCod": matDtlObj.find('td').eq(1).text(),
            "matNam": matDtlObj.find('td').eq(2).text(),
            "matUnt": matDtlObj.find('td').eq(3).text(),
            "pchsNum": matDtlObj.find('td').eq(4).text(),
            "dlvAdr": matDtlObj.find('td').eq(5).text(),
            "dlvDteStr": matDtlObj.find('td').eq(6).text(),
            "techServ": matDtlObj.find('td').eq(7).text(),
            "memo": matDtlObj.find('td').eq(8).text()
        };
        return matDtl;
    },

    displayMatDtl: function (matDtl) {
        let resultHtml = matDtlTpl(matDtl);
        $('.matDtlTable').html(resultHtml);
        $('#matDtlModal').modal('show');
        jQuery('.datepicker').datetimepicker({
            language: 'zh-CN',
            weekStart: 1,
            todayBtn: 1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 2, //0表示分钟（默认），1表示小时，而2表示天
            forceParse: 0,
            showMeridian: 1,
            format: 'yyyy-mm-dd'///
        });
    },

    displayMatInfs : function (matList) {

        let resultHtml = matInfsTpl({matInfs: matList});
        $('.matInfsDiv').html(resultHtml);

        //删除整行
        jQuery('.delete').click(function () {
            var _this = jQuery(this);
            _this.parent('td').parent('tr').remove();
        });

        // 编辑
        $(".editMatDtl").on("click", function () {
            var matDtlObj = jQuery(this).parent('td').parent('tr').addClass("active");
            var matDtl = projEditObj.getMatDtlInf(matDtlObj);
            projEditObj.displayMatDtl(matDtl);
            jQuery('.addOrModMatDtl').attr('addOrMod', 'mod');
            jQuery('.matDtlTable .matCod').attr("disabled","disabled");
        });
    },

    displayManagedCompanies : function () {
        let managedCompanies = JSON.parse(orgList);
        if (orgJsonObj.length == null || orgJsonObj.length <= 0) {
            alert("该采购员无所辖公司");
            location.href = HOST_FRT+'/bid_online/proj_list.html';
        }

        var matOrgin = $(".matOrgin").val();
        $('.matInfsDiv').html('');
        if (matOrgin === '0') {
            let resultHtml = suitCompaniesTpl({suitCompanies: []});
            $('.suitCompaniesDiv').html(resultHtml);
            $('.suitCompaniesDiv').hide();
            $('.suitCompaniesDescDiv').html("<p>物料来源为请购需求时，适用公司同发起公司</p>");
            $('.suitCompaniesDescDiv').show();
        } else {
            let resultHtml = suitCompaniesTpl({suitCompanies: managedCompanies});
            $('.suitCompaniesDiv').html(resultHtml);
            $('.suitCompaniesDescDiv').hide();
            $('.suitCompaniesDiv').show();
        }
    },

    displayDesignatedSplrs : function (designatedSplrs) {
        let resultHtml = designatedSplrsTpl({designatedSplrs: designatedSplrs});
        $('.designatedSplrsDiv').html(resultHtml);

        //删除整行
        jQuery('.deleteDesignatedSplr').click(function () {
            var _this = jQuery(this);
            _this.parent('td').parent('tr').remove();
        });
    },

    getAtches : function () {
        var atches =[];
        var atchObjs = jQuery('#atches tr');

        for (var j = 0; j < atchObjs.length; j++) {
            atches.push({
                "atchUrl" : atchObjs.eq(j).attr('atchUrl')
                , "atchNam" : atchObjs.eq(j).attr('atchNam')
            });
        }

        return atches;
    },

    displayAtches : function (atches) {
        $.each(atches,function(idx,val){
            val.atchUrlFmt = HOST_FILE + val.atchUrl;
        });
        let resultHtml = atchesTpl({atches: atches});
        $('.atchFilesDiv').html(resultHtml);
        //删除整行
        jQuery('.deleteAtch').click(function () {
            var _this = jQuery(this);
            _this.parent('td').parent('tr').remove();
        });
    },

    changeBidRngTyp : function () {
        var bidRngTyp = jQuery('.bidRngTyp').val();
        if (bidRngTyp === '0') {
            jQuery('.designatedSplrsBtnFormActionArea').hide();
            jQuery('.designatedSplrsDiv').hide();
            projEditObj.displayDesignatedSplrs([]);
        } else if (bidRngTyp === '1') {
            if(!jQuery('.matTyp.matkl2').val()){
                alert("请先选择物料分类");
                jQuery('.bidRngTyp').val('0');
                return;
            }
            jQuery('.designatedSplrsBtnFormActionArea').show();
            jQuery('.designatedSplrsDiv').show();
            projEditObj.displayDesignatedSplrs([]);
        }
    },

    setMatOri : function () {
        var matOrgin = $(".matOrgin").val();
        $('.matInfsDiv').html('');

        if (matOrgin === '0') {
            jQuery(".selectMat").show();
            jQuery(".addMatDtl").hide();
            jQuery(".importedMatInfs").hide();

        } else {
            jQuery(".selectMat").hide();
            jQuery(".addMatDtl").show();
            jQuery(".importedMatInfs").show();
        }

        // projEditObj.displayManagedCompanies();
    },

    getMatInfs : function () {
        let matInfs = [];
        let matInfsObj = jQuery('#matInfs tr');
        for (let j = 0; j < matInfsObj.length; j++) {
            matInfs.push({
                "projId":projId,
                "reqId": matInfsObj.eq(j).find('td').eq(0).text(),
                "matCod": matInfsObj.eq(j).find('td').eq(1).text(),
                "matNam": matInfsObj.eq(j).find('td').eq(2).text(),
                "matUnt": matInfsObj.eq(j).find('td').eq(3).text(),
                "pchsNum": matInfsObj.eq(j).find('td').eq(4).text(),
                "dlvAdr": matInfsObj.eq(j).find('td').eq(5).text(),
                "dlvDteStr": matInfsObj.eq(j).find('td').eq(6).text(),
                "techServ": matInfsObj.eq(j).find('td').eq(7).text(),
                "memo": matInfsObj.eq(j).find('td').eq(8).text()
            });
        }
        return matInfs;
    },

    setGrdRul : function() {

        let grdRul = $(".grdRul").val();

        if (grdRul === '0') {
            $('#grdTabDesc').html('');
            $('#grdTab').html('');
        } else if (grdRul === '1') {    // -----------------20171211--------
            // $('#grdTabDesc').html('<span class="red">* </span>专家评标表选择：');
            // $('#grdTab').html('<select data-placeholder="请选择评标表" class="span12 grdTab">\n' +
            //     '<option value="">==请选择专家评标表==</option>\n' +
            //     '</select>');
        }
    }
};


jQuery('.designatedSplrsBtn').click(function () {
    jQuery.ajax({
        url: HOST_ADDR+'/cpmp/mat/splrByMatType',
        type: 'get',
        dataType: 'json',
        contentType:"application/json",
        headers: {
            splrSts:"03,05",
            matType: jQuery('.matTyp.matkl2').val(),
            'access_token': token,'login_type':'ums'
        },
        success: function(resp){
            if (!resp.success) {
                alert(resp.msgCod+' '+resp.msgInf);
                return;
            }
            console.log(resp);

            // TODO

            $('.designateSplrsTable').html('');
            let resultHtml = selectSplrsTpl({selectSplrs: resp.data});
            $('.designateSplrsTable').html(resultHtml);

            $('#designateSplrsModal').modal('show');
        },
        error:function(err){

            console.log(err);
        }
    });
});

jQuery('.designateSplrs_ok').click(function () {

    var designatedSplrs =[];
    var splrs = jQuery('#selectSplrs tr');

    for (var j = 0; j < splrs.length; j++) {
        // 判断是否选中
        var checked = splrs.eq(j).find('td').eq(0).find('input').is(':checked');
        if (checked) {
            designatedSplrs.push({
                "splrId" : splrs.eq(j).find('td').eq(1).text()
                , "splrNam" : splrs.eq(j).find('td').eq(4).text()
            });
        }
    }

    projEditObj.displayDesignatedSplrs(designatedSplrs);

    $('#designateSplrsModal').modal('hide');
});

// 单笔新增/修改物料
jQuery('.saveMatDtl').click(function () {

    let reqId = jQuery('.matDtlTable .reqId').val();
    let matCod = jQuery('.matDtlTable .matCod').val();
    let matNam = jQuery('.matDtlTable .matNam').val();
    let matUnt = jQuery('.matDtlTable .matUnt').val();
    let pchsNum = jQuery('.matDtlTable .pchsNum').val();
    let dlvAdr = jQuery('.matDtlTable .dlvAdr').val();
    let dlvDteStr = jQuery('.matDtlTable .dlvDteStr').val();
    let techServ = jQuery('.matDtlTable .techServ').val();
    let memo = jQuery('.matDtlTable .memo').val();
    if (matCod == '') {
        alert("物料编码不得为空!");
        return;
    }
    if (matNam == '') {
        alert("物料名称不得为空!");
        return;
    }
    if (matUnt == '') {
        alert("物料单位不得为空!");
        return;
    }
    if (pchsNum =='') {
        alert('采购数量不得为空!');
        return;
    }
    if (dlvAdr =='') {
        alert('交货地址不得为空!');
        return;
    }
    if (dlvDteStr =='') {
        alert('交货日期不得为空!');
        return;
    }
    let matInf = {
        "reqId" : reqId,
        "matCod" : matCod,
        "matNam" : matNam,
        "matUnt" : matUnt,
        "pchsNum" : pchsNum,
        "dlvAdr": dlvAdr,
        "dlvDteStr": dlvDteStr,
        "techServ" : techServ,
        "memo" : memo
    };

    console.log("matInf: " + matInf);
    let matInfs = projEditObj.getMatInfs();
    let type = jQuery('.addOrModMatDtl').attr('addOrMod');
    console.log('type: ' + type);
    if (type === 'add') {
        // for (let i = 0; i < matInfs.length; i++) {
        //     if (matInfs[i].matCod === matCod) {
        //         alert("该物料已存在，请修改!");
        //         return ;
        //     }
        // }
        matInfs.push(matInf);
        projEditObj.displayMatInfs(matInfs);
    } else {
        var emObj = $(".matInfsDiv tr.active");
            emObj.find('td').eq(1).html(matCod);
            emObj.find('td').eq(2).html(matNam);
            emObj.find('td').eq(3).html(matUnt);
            emObj.find('td').eq(4).html(pchsNum);
            emObj.find('td').eq(5).html(dlvAdr);
            emObj.find('td').eq(6).html(dlvDteStr);
            emObj.find('td').eq(7).html(techServ);
            emObj.find('td').eq(8).html(memo);
        emObj.removeClass("active");
        // for (let i = 0; i < matInfs.length; i++) {
        //     if (matInfs[i].matCod === matCod) {
        //         matInfs[i].matNam = matNam;
        //         matInfs[i].matUnt = matUnt;
        //         matInfs[i].pchsNum = pchsNum;
        //         matInfs[i].dlvAdr = dlvAdr;
        //         matInfs[i].dlvDteStr = dlvDteStr;
        //         matInfs[i].techServ = techServ;
        //         matInfs[i].memo = memo;
        //         break;
        //     }
        // }
    }

    console.log('matIns: ' + matInfs);
    jQuery('#matDtlModal').modal('hide');

});


jQuery('.getExcelTpl03').click(function () {
    window.open(HOST_FILE + "atch/matInfo_template.xls");
});

jQuery('.getExcelTpl07').click(function () {
    window.open(HOST_FILE + "atch/matInfo_template.xlsx");
});

jQuery('.viewExRate').click(function () {
    alert('敬請期待!');
    // window.open(HOST_ADDR + "/show", "_blank");
});

jQuery('.selectMat').click(function () {

    ProjEdit.renderList();
    jQuery('#myModal').modal('show');

});

App.init();
ProjEdit.init();
// projEditObj.init();
jQuery('.logOut').attr('href','../logins/login.html');